from collections import defaultdict
from collections import OrderedDict

dict1 = {'name': 'zhangsan', 'no': 11, 'age': 18}

print(dict1)


# print(dict1.get('name'))
# print(dict1['age'])

# print(dict1.get('name1'))
# print(dict1['age1'])

def fun():
    return '没有值'


# dict2 = defaultdict(lambda: '没有值')  # callable  function
#
# dict2['name'] = 'lisi'
# dict2['age'] = 11
# dict2['no'] = 110

# print(dict2)

# print(dict2['name'])
# print(dict2['age'])
# print(dict2['name1'])
# print(dict2['age1'])

# for item in dict2.items():
#     print(item)
#     key, value = item
#     print(key)
#     print(value)
# print('*' * 20)

# dic = dict()
# dict3 = {'name': 'zhangsan', 'age': 18, 'no': 11}
# dict3['am'] = 'wobuxin'
# dict3['aaa'] = 'hhh'
# print(dict3)

# print(OrderedDict)  # <class 'collections.OrderedDict'>
# print(type(OrderedDict))  # <class 'type'>
#
# print(issubclass(OrderedDict, dict))  # True

# 'banana': 3, 'apple': 4, 'pear': 1, 'orange': 2
# d = OrderedDict()
# d['banana'] = 3
# d['apple'] = 4
# d['pear'] = 1
# d['orange'] = 2

d = {'banana': 3, 'apple': 4, 'pear': 1, 'orange': 2}

# print(d)
# dd = OrderedDict(sorted(d.items(), key=lambda t: t[0]))
# print(dd)
# vv = OrderedDict(sorted(d.items(), key=lambda t: t[1]))
# print(vv)
# d['e'] = 'e'
# d.pop('apple')
# d['apple'] = 10
print(d)

for k, v in d.items():
    print(k)
    print(v)
